import apis from './indexapi2'
const BASE_URL = window._editHtml || '' // 确保已正确定义 window.url
const api = apis(BASE_URL)
// 登录
export const login = async (data) => {
  try {
    // 参数顺序：url, params, data
    const response = await api.hDoPost('/login', '', data)
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
//获取近七日预约情况
export const getAppointment = async () => {
  try {
    const response = await api.hDoPost('/reservation/userreservation/getAppointment', '')
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
//获取预约记录
export const getUsageRecords = async () => {
  try {
    const response = await api.hDoPost('/reservation/userreservation/getUsageRecords', '')
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}

//根据设备名字查询设备信息
export const getDeviceByName = async (id) => {
  try {
    const response = await api.hDoPost('/obixDevice/obixDevice/getDeviceInfo/' + id, '', '')
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
//根据设备url设置设备参数
export const getDeviceInfoByUrl = async (data) => {
  try {
    const response = await api.hDoPost('/obixDevice/obixDevice/getDeviceInfoByUrl', '', data)
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
//根据设备类型获取设备数据列表
export const getDeviceType = async () => {
  try {
    const response = await api.hDoGet('/obixDevice/obixDevice/getDeviceType', '')
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
//获取设备类型统计数量
export const getCountType = async () => {
  try {
    const response = await api.hDoGet('/obix/type/getCount', '')
    return response
  } catch (error) {
    throw error // 重新抛出错误供外层处理
  }
}
